package com.tequila.bops.controller;

import com.tequila.core.service.SystemService;
import com.tequila.domain.dto.UploadFileDto;
import fe.core.ApiResponse;
import fe.core.exception.BizException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
@RequestMapping("/sys")
public class SystemController {
    @Resource
    private SystemService systemService;

    @RequestMapping("/uploadImage")
    public ApiResponse uploadImage(MultipartFile file, String bucket, @RequestParam(required = false) String category) {
        UploadFileDto uploadFileDto = null;
        try {
            uploadFileDto = UploadFileDto.buildUploadFileDto(bucket,category,file.getInputStream(),file.getOriginalFilename(),file.getContentType(),file.getBytes());
        } catch (IOException e) {
            throw new BizException("get file inputStream error!");
        }
        return ApiResponse.successApiResponse().withData(systemService.upload(uploadFileDto));

    }


}
